package com.adv.ems.model.vo;

import com.adv.ems.db.entity.*;
import com.adv.ems.utils.EmsUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;

@Data
public class BaseEnergyFeeVO {
    private List<Item> list;

    public BaseEnergyFeeVO() {
        this.list = new ArrayList<Item>();
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Item {
        private String energyName;
        private Long energyId;
        private List<Info> data;

        public Item(EnergyInfoDO energyInfoDO, List<Info> data, String acceptLanguage) {
            this.energyId = energyInfoDO.getId();
            this.data = data;
            this.setEnergyName(EmsUtil.multilingual(energyInfoDO.getNameInfo(), acceptLanguage));
        }
    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Info extends EnergyFeeInfoDO {
        private String buildingName;
        private String instituteName;
        private String energyName;

        public Info(EnergyFeeInfoDO fee, InstituteInfoDO instituteInfoDO, BuildingInfoDO buildingInfo, EnergyInfoDO energyInfoDO, String acceptLanguage) {
            BeanUtils.copyProperties(fee, this);
            if (instituteInfoDO != null) {
                this.setInstituteName(EmsUtil.getNameInfo(instituteInfoDO.getNameInfo(), acceptLanguage).getShortName());
            }
            if (buildingInfo != null) {
                this.setBuildingName(EmsUtil.getNameInfo(buildingInfo.getNameInfo(), acceptLanguage).getShortName());
            }
            if (energyInfoDO != null) {
                this.setEnergyName(EmsUtil.multilingual(energyInfoDO.getNameInfo(), acceptLanguage));
            }
        }
    }
}
